package dominion.kingdom;

import dominion.Action;
import dominion.Card;
import dominion.CardTypes;
import dominion.Dominion;
import dominion.Player;

public class Adventurer implements Action {

	@Override
	public void execute(Dominion dominion) {
		Player player = dominion.current();
		int times = 0;
		int revealTime = 0;
		int deckSize = player.deck().size() + player.grave().size();
		while (times < 2 && revealTime < deckSize) {
			revealTime++;
			Card c = player.reveal(dominion);
			if (c == null) {
				break;
			}
			if (CardTypes.isTresure(c)) {
				times++;
				player.hand().add(c);
			} else {
				player.discard(c);
			}
		}
	}

	@Override
	public CardTypes getType() {
		return CardTypes.Adventurer;
	}

	@Override
	public String toString() {
		return getType().name();
	}
}
